<%@ page contentType="text/html;charset=utf-8" %>
<%@ page import="ut.data.User" %>
<%@ page import="ut.data.AbuseReport" %>
<%@ page import="ut.util.DateTime" %>
<%
	User user = (User)session.getAttribute("user");
	if(user == null){
		response.sendRedirect("/");
		return;
	}
	int p;
	try{
		p = Integer.parseInt(request.getParameter("p"));
	}catch(NumberFormatException e){
		p = 1;
	}
	
	int maxPage = AbuseReport.getMaxAbuseReportPage(10);
	if(p > maxPage){
		p = maxPage;
	}
%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>UT終極一翻！ | 申訴記錄</title>
	<link rel="stylesheet" type="text/css" href="/style.css" media="all" />
	<link rel="stylesheet" type="text/css" href="/css/task-list.css" media="all" />
	<script type="text/javascript" src="/js/Utility.js"></script>
	<script type="text/javascript" src="/js/Message.js"></script>
	<script type="text/javascript" src="/js/Ajax.js"></script>
	<script type="text/javascript" src="/js/Button.js"></script>
	<script type="text/javascript" src="/js/Account.js"></script>
	<script type="text/javascript" src="/js/Admin.js"></script>
	<script type="text/javascript" src="/script.js"></script>
</head>
<body onload="init();">
<%@ include file="/include/banner.jsp" %>
	<div class="content">
		<div class="title">申訴記錄</div>
		<div class="page">
<%
	StringBuilder pageOptions = new StringBuilder("");
	if(p > 1){
		pageOptions.append("<a href=\"./?page=1\">第一頁</a>");
		pageOptions.append("<a class=\"page-link\" href=\"./?page=" + (p-1) + "\">上一頁</a>");
	}else{
		pageOptions.append("<span class=\"inactive\">第一頁</span><span class=\"page-link inactive\">上一頁</span>");
	}
	int startPage = (p - 2 > 0) ? p - 2 : 1;
	int endPage = startPage + 4;
	if(endPage > maxPage){
		startPage = startPage - (endPage - maxPage);
		endPage = maxPage;
	}
	for(int i = startPage; i <= endPage; i++){
		if(i < 1){
			continue;
		}else if(i == p){
			pageOptions.append("<span class=\"page-link current\">" + i + "</span>");
		}else{
			pageOptions.append("<a class=\"page-link\" href=\"./?page=" + i + "\">" + i + "</a>");
		}
	}
	if(p < maxPage){
		pageOptions.append("<a class=\"page-link\" href=\"./?page=" + (p+1) + "\">下一頁</a>");
		pageOptions.append("<a class=\"page-link\" href=\"./?page=" + maxPage + "\">最後頁</a>");
	}else{
		pageOptions.append("<span class=\"page-link inactive\">下一頁</span><span class=\"page-link inactive\">最後頁</span>");
	}
	out.print(pageOptions.toString());
%>
		</div>
<%
	AbuseReport[] reports = AbuseReport.getAbuseReports(10, p);
	if(reports[0] == null){
%>
		<div class="list block">
			<div class="block-center">目前沒有任何待處理的申訴紀錄</div>
		</div>
<%
	}else{
%>
		<div class="list">
			<table cellspacing="0" cellpadding="5">
				<tr>
					<td class="title">申訴者</td>
					<td class="title">申訴類型</td>
					<td class="title">申訴對象</td>
					<td class="title">申訴時間</td>
					<td class="title">動作</td>
				</tr>
<%
		for(int i = 0; i < reports.length; i++){
			if(reports[i] == null){
				break;
			}
%>
				<tr>
					<td style="cursor:auto"><a target="_blank" href="/account/member-info.jsp?uid=<%= reports[i].reporter %>"><%= User.getUserName(reports[i].reporter) %></a></td>
					<td style="cursor:auto"><%= reports[i].type %></td>
					<td style="cursor:auto"><%= reports[i].target %></td>
					<td style="cursor:auto"><%= DateTime.toDateTime(reports[i].time) %></td>
					<td style="cursor:auto">
						<button class="button" onclick="Admin.abuseReportProcessed(<%= reports[i].id %>, this);"
							onmousedown="this.style.borderStyle='inset'"
							onmouseup="this.style.borderStyle='outset'"
							onmouseout="this.style.borderStyle='outset'" />
							OK
						</button>
					</td>
				</tr>
<%
		}
%>
			</table>
		</div>
<%
	}
%>
		<div class="page">
<%
	out.print(pageOptions.toString());
%>
		</div>
<%@ include file="/include/foot.jsp" %>
	</div>
</body>
</html>